package com.mroapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.mroapp.R;
import com.mroapp.base.BaseActivity;
import com.mroapp.utils.StringUtils;

/**
 * Created by apple on 16/6/12.
 */

public class LoginActivity extends BaseActivity  {
    private Button btn_login;
    private EditText telephone;
    private TextView validate_code;
    private Button again_send;
    private CheckBox checkbox_agree;
    private TextView xieyiTV;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        initView();

    }
    public  void initView(){
        btn_login=(Button)findViewById(R.id.btn_login);
        btn_login.setOnClickListener(this);
        telephone=(EditText)findViewById(R.id.telephone);
        validate_code=(TextView)findViewById(R.id.validate_code);
        again_send=(Button)findViewById(R.id.again_send);
        again_send.setOnClickListener(this);
        checkbox_agree=(CheckBox)findViewById(R.id.checkbox_agree);
        checkbox_agree.setOnClickListener(this);
        xieyiTV=(TextView)findViewById(R.id.xieyiTV);
        xieyiTV.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.btn_login:
//                if(!StringUtils.phoneValidate(telephone.getText().toString())){
//                    Toast.makeText(this,"请输入正确的手机号",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if(StringUtils.isEmpty(validate_code.getText().toString())){
//                    Toast.makeText(this,"验证码不能为空",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if(!checkbox_agree.isChecked()){
//                    Toast.makeText(this,"请同意魔龙机器人用户协议",Toast.LENGTH_SHORT).show();
//                    return;
//                }
                login(telephone.getText().toString(),validate_code.getText().toString());
                break;
            case R.id.again_send:
                String number=telephone.getText().toString();
                if(!StringUtils.phoneValidate(number)){
                    Toast.makeText(this,"请输入正确的手机号码",Toast.LENGTH_SHORT).show();
                    return;
                }
                requestCode(number);
                break;
            case R.id.xieyiTV:
                Intent intent=new Intent(this, UserProtocolActivity.class);
                startActivity(intent);
                break;
        }
    }

    /**
     * 请求验证码
     * @param number
     */
    private void requestCode(String number){


    }

    /**
     * 请求登录
     * @param number  13167279552
     * @param code  1234
     */
    private void login(final String number,final String code){
        showLoadingDialog(true);
        if(code.equals("1234")){
            Intent intent=new Intent(LoginActivity.this,HomeActivity.class);
            startActivity(intent);
            spUtils.put("login",true);
            LoginActivity.this.finish();
        }

    }

}
